/**
 * 
 */
package study;

/**
 * @author admin
 *
 */
import java.io.*;
public class FileLengthTest_2 {
	private ArryTest at=new ArryTest(100);
	
	private int size;
	
	private String[] fileNames;
	
	public String[] getStringArray(){
		
		int len=getCont();
		return fileNames=new String[len];
	}
	
	public int getRealFileCont(String scr){
		int cont=0;
		File file=new File(scr);
		if(file==null){
			return cont;
		}
		if(file.isDirectory()){
			File[] files=file.listFiles();
			for(int i=0;i<files.length;i++){
				if(files[i].isDirectory()){
					String filesName=files[i].getAbsolutePath();
					getRealFileCont(filesName);
				}
				if(files[i].isFile()){
				cont++;
				}
			}
		}
		if(file.isFile()){
			cont++;
		}
		return cont;
		
	}
	public int getCont(){
		File[] file=File.listRoots();
		for(int i=0;i<file.length;i++){
			String name=file[i].getAbsolutePath();
			size+=getRealFileCont(name);
		}
		return size;
	}
	
	public Long getAllFileLength(String scr){
		int c=0;
		Long len=0L;
		File filename=new File(scr);
		if(filename==null){
			return len;
		}
		if(filename.isDirectory()){
			File[] files=filename.listFiles();
			if(files==null){
				return len;
			}
			for(int i=0;i<files.length;i++){
				if(files[i]==null){
					return len;
				}
				if(files[i].isDirectory()){
					String name=files[i].getAbsolutePath();
					getAllFileLength(name);
				}
				if(files[i].isFile()){
				
				fileNames[c++]=files[i].getAbsolutePath();
				len+=files[i].length();
				}
			}
		}
		if(filename.isFile()){
		fileNames[c++]=filename.getAbsolutePath();
		len+=filename.length();
		}
		return len;
	}
	
	public void getJavaFile(String suffix){
		int j=0;
		for(int i=0;i<size;i++)
			if(fileNames[i].endsWith(suffix)){
				
				at.insertObjectToArry(j++, fileNames[i]);
			}
	}
	
	
	

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		ArryTest at=new ArryTest(100);
		Long length=0L;
		//String name;
		boolean flag=true;
		// TODO Auto-generated method stub
		FileLengthTest_2 ft=new FileLengthTest_2();
		File[] rootFile=File.listRoots();
		for(int i=0;i<rootFile.length;i++){
		String scr=rootFile[i].getAbsolutePath();
		length+=ft.getAllFileLength(scr);
		
		}
		System.out.println(length);
		while(flag){
			int i=0;
			String names=(String)at.getObjectInArry(i++);
			if(names==null){
				flag=false;
				return;
			}
			System.out.println(names);
		}

	}

}
